//
//  WeightEntryCell.m
//  IWeighMyself
//
//  Created by Francisco Gindre on 8/30/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "WeightEntryCell.h"

#import "IWeighMyselfAppDelegate.h"

@implementation WeightEntryCell
@synthesize dateLabel;
@synthesize weightLabel;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
        // Initialization code
		
		self.dateLabel = [[UILabel alloc]init];
		self.weightLabel = [[UILabel alloc] init];
		
    }
    return self;
}

-(id)initWithWeight:(Weight*)aWeight {
	IWeighMyselfAppDelegate *appDelegate;
	if (self= [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WeightEntryCellIdentifier"]) {
		/*
		 set date label to the weight's date
		 */
		[self.dateLabel setText:[NSDateFormatter localizedStringFromDate:[aWeight dateLogged] 
															   dateStyle:NSDateFormatterMediumStyle 
															   timeStyle:NSDateFormatterNoStyle]];
		NSString *unit;
		appDelegate = [[[UIApplication sharedApplication] delegate] retain];
		
		/*
		 set the weight and unit for this weight
		 */
		
		if ([appDelegate isKilosWeightSelectedUnit]) {
			unit = NSLocalizedString(@"WeightUnitKilos",@"");
			[self.weightLabel setText:[[aWeight.weightInKilos stringValue]stringByAppendingString:unit]];
		} else {
			unit = NSLocalizedString(@"WeightUnitPounds",@"");
			[self.weightLabel setText:[[aWeight.weightInPounds stringValue]stringByAppendingString:unit]];
		}
		//release memory
		[appDelegate release];
		[unit release];
	}
	return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
	
    [super setSelected:selected animated:animated];
	
    // Configure the view for the selected state
}



- (void)dealloc {
    [super dealloc];
}




@end
